翻訳と辞書
Words near each other
・ Tajuria mantra
・ Tajuria matsutaroi
・ Tajuria matsutaroi motokoae
・ Tajuria mizunumai
・ Tajuña
・ Tajwal
・ Tajwal Tarli
・ Tajwal Utli
・ Tajwan, Kuyavian-Pomeranian Voivodeship
・ Tajwid
・ Tajzara Lake
・ Tajín (seasoning)
・ Tajči
・ Tajęcina
・ Tak
Tak (function)
・ Tak (town)
・ Tak Aghaj
・ Tak Aghaj, West Azerbaijan
・ Tak Aghaj, Zanjan
・ Tak Airport
・ Tak and Co Inc v AEL Corp Ltd
・ Tak and the Guardians of Gross
・ Tak and the Power of Juju
・ Tak and the Power of Juju (TV series)
・ Tak Baghestan
・ Tak Bai
・ Tak Bai District
・ Tak Bai incident
・ Tak Bolagh


Dictionary Lists
翻訳と辞書 辞書検索 [ 開発暫定版 ]
スポンサード リンク

Tak (function) : ウィキペディア英語版
Tak (function)
In computer science, the Tak function is a recursive function, named after Ikuo Takeuchi (竹内郁雄). It is defined as follows:
\tau (x,y,z) = \begin
\tau (\tau (x-1,y,z) ,\tau (y-1,z,x) ,\tau (z-1,x,y) ) & \text y < x \\
z & \text
\end


def tak( x, y, z)
if y < x
tak(
tak(x-1, y, z),
tak(y-1, z, x),
tak(z-1, x, y)
)
else
z
end
end

This function is often used as a benchmark for languages with optimization for recursion.〔

〕〔
("Recursive Methods" )
by Elliotte Rusty Harold

==tak() vs. tarai()==
The original definition by Takeuchi was as follows:

def tarai( x, y, z)
if y < x
tarai(
tarai(x-1, y, z),
tarai(y-1, z, x),
tarai(z-1, x, y)
)
else
y # not z!
end
end

tarai is short for ''tarai mawashi'', "to pass around" in Japanese.
John McCarthy named this function tak() after Takeuchi.〔

However, in certain later references, the y somehow got turned into the z.
This is a small, but significant difference because the original version benefits significantly by lazy evaluation.
Though written in exactly the same manner as others, the Haskell code below runs much faster.

tarai :: Int -> Int -> Int -> Int
tarai x y z
| x <= y = y
| otherwise = tarai(tarai (x-1) y z)
(tarai (y-1) z x)
(tarai (z-1) x y)

You can easily accelerate this function via memoization yet lazy evaluation still wins.
The best known way to optimize tarai is to use mutually recursive helper function as follows.

def laziest_tarai(x, y, zx, zy, zz)
unless y < x
y
else
laziest_tarai(tarai(x-1, y, z),
tarai(y-1, z, x),
tarai(zx, zy, zz)-1, x, y)
end
end
def tarai(x, y, z)
unless y < x
y
else
laziest_tarai(tarai(x-1, y, z),
tarai(y-1, z, x),
z-1, x, y)
end
end

Here is an efficient implementation of tarai() in C:

int tarai(int x, int y, int z)

Note the additional check for (x <= y) before z (the third argument) is evaluated, avoiding unnecessary recursive evaluation.

抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)
ウィキペディアで「Tak (function)」の詳細全文を読む



スポンサード リンク
翻訳と辞書 : 翻訳のためのインターネットリソース

Copyright(C) kotoba.ne.jp 1997-2016. All Rights Reserved.